package com.wangfugui.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangfugui.mybatisplus.common.PageRequest;
import com.wangfugui.mybatisplus.service.IBaseService;

import java.util.function.Function;

public class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T>
        implements IBaseService<T> {

    @Override
    public IPage<T> page(Page<T> page, Wrapper<T> queryWrapper) {
        return baseMapper.selectPage(page, queryWrapper);
    }

    // 添加带条件的通用分页方法
    public IPage<T> pageWithCondition(Page<T> page, Function<LambdaQueryWrapper<T>, LambdaQueryWrapper<T>> condition) {
        LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>();
        wrapper = condition.apply(wrapper);
        return this.page(page, wrapper);
    }
}